var WicketConGoogle;
if (!WicketConGoogle) {
	WicketConGoogle = {};
} else if (typeof WicketConGoogle !== "object") {
	throw new Error("WicketConGoogle already exists but is not an object");
}

WicketConGoogle.maps = {};

WicketConGoogle.eventListeners = {};

WicketConGoogle.eventHooks = {};

WicketConGoogle.Map2 = function(id, divId) {
	WicketConGoogle.maps[id] = {
		map : new google.maps.Map2(document.getElementById(divId)),
		controls : {},
		overlays : {},

		onEvent : function(params) {
			params['center'] = this.map.getCenter();
			params['bounds'] = this.map.getBounds();
			params['zoom'] = this.map.getZoom();
			params['currentMapType'] = this.getMapTypeString(this.map
					.getCurrentMapType());
			params['infoWindow.hidden'] = this.map.getInfoWindow().isHidden();

			callBack = WicketConGoogle.callbackUrl;
			for ( var key in params) {
				callBack = callBack + '&' + key + '=' + params[key];
			}

			wicketAjaxGet(callBack, function() {
			}, function() {
			});
		},

		addListener : function(listenerId, event) {
			var that = this;
			WicketConGoogle.eventListeners[listenerId] = google.maps.Event
					.addListener(this.map, event, function() {
						var params = {};
						params['event'] = event;
						params['listenerId'] = listenerId;
						for ( var p = 0; p < arguments.length; p++) {
							if (arguments[p] != null) {
								params['argument' + p] = arguments[p];
							}
						}

						that.onEvent(params);
					});
		},

		getMapTypeString : function(mapType) {
			switch (mapType) {
			case G_NORMAL_MAP:
				return 'G_NORMAL_MAP';
				break;
			case G_SATELLITE_MAP:
				return 'G_SATELLITE_MAP';
				break;
			case G_HYBRID_MAP:
				return 'G_HYBRID_MAP';
				break;
			default:
				return 'unknown';
				break;
			}
		}
	}
}

WicketConGoogle.EventHook = function(id, callbackUrl) {
	WicketConGoogle.eventHooks[id] = {
			callbackUrl : callbackUrl
	}
}